﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DiarySocial.Models;

namespace DiarySocial.Controllers
{
    public class AboutController : Controller
    {
        private DiaryEnties db = new DiaryEnties();

        //
        // GET: /About/

        public ActionResult Index()
        {
            var extrauserinformations = db.ExtraUserInformations.Include(e => e.Avatar).Include(e => e.UserProfile);
            return View(extrauserinformations.ToList());
        }

        //
        // GET: /About/Details/5

        public ActionResult Details(int id = 0)
        {
            ExtraUserInformation extrauserinformation = db.ExtraUserInformations.Find(id);
            if (extrauserinformation == null)
            {
                return HttpNotFound();
            }
            return View(extrauserinformation);
        }

        //
        // GET: /About/Create

        public ActionResult Create()
        {

            
            ViewBag.AvatarId = new SelectList(db.Media, "MediaId", "Path");
            ViewBag.UserId = User.Identity;
            return View();
        }

        //
        // POST: /About/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(ExtraUserInformation extrauserinformation)
        {
            if (ModelState.IsValid)
            {
                db.ExtraUserInformations.Add(extrauserinformation);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.AvatarId = new SelectList(db.Media, "MediaId", "Path", extrauserinformation.AvatarId);
            ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", extrauserinformation.UserId);
            return View(extrauserinformation);
        }

        //
        // GET: /About/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ExtraUserInformation extrauserinformation = db.ExtraUserInformations.Find(id);
            if (extrauserinformation == null)
            {
                return HttpNotFound();
            }
            ViewBag.AvatarId = new SelectList(db.Media, "MediaId", "Path", extrauserinformation.AvatarId);
            ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", extrauserinformation.UserId);
            return View(extrauserinformation);
        }

        //
        // POST: /About/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(ExtraUserInformation extrauserinformation)
        {
            if (ModelState.IsValid)
            {
                db.Entry(extrauserinformation).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.AvatarId = new SelectList(db.Media, "MediaId", "Path", extrauserinformation.AvatarId);
            ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", extrauserinformation.UserId);
            return View(extrauserinformation);
        }

        //
        // GET: /About/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ExtraUserInformation extrauserinformation = db.ExtraUserInformations.Find(id);
            if (extrauserinformation == null)
            {
                return HttpNotFound();
            }
            return View(extrauserinformation);
        }

        //
        // POST: /About/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            ExtraUserInformation extrauserinformation = db.ExtraUserInformations.Find(id);
            db.ExtraUserInformations.Remove(extrauserinformation);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}